package com.hqyj.springBoot.modules.account.service.impl;

import com.hqyj.springBoot.modules.common.vo.Result;
import com.hqyj.springBoot.modules.account.dao.UserRoleDao;
import com.hqyj.springBoot.modules.account.entity.UserRole;
import com.hqyj.springBoot.modules.account.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserRoleServiceImpl implements UserRoleService {

    @Autowired
    private UserRoleDao userRoleDao;

    @Override
    @Transactional
    public Result<UserRole> insertUserRole(UserRole userRole) {

        UserRole temp = userRoleDao.selectUserRoleById(userRole.getId());
        if (temp != null){
            return new Result<>(Result.ResultStatus.FAILED.code, "UserRole is repeat");
        }

        userRoleDao.insertUserRole(userRole);

        return new Result<>(Result.ResultStatus.SUCCESS.code, "Insert success",userRole);
    }
}
